/**
 * @Description: 全局自动注册组件，前缀加上 g-
 * @Author BPF
 * @create 2021/8/20 21:49
 */
import { Vite } from '@bianpengfei/utils'
import setting from '/src/setting'
const { requireAllModule } = Vite
export default {
  install: app => {
    const prefix = setting.vueGlobalComponentPrefix
    requireAllModule({
      requireContext: import.meta.globEager('/src/components/base/**/*.vue'),
      exclude: []
    })
      .concat(
        requireAllModule({
          requireContext: import.meta.globEager('/src/components/business/**/*.vue'),
          exclude: []
        })
      )
      .forEach(v => {
        const _default = v?.default
        if (_default?.name) {
          const name = _default?.name?.includes?.(prefix) ? _default?.name : `${prefix}${_default?.name}`
          app.component(name, _default)
        }
      })
  }
}
